﻿using System;
using System.Collections.Generic;
using System.Text;

namespace DataStructureAndAlgorithm.递归
{
    public class TestHanoi
    {
        public void DoTest()
        {
            Hanoi(3, "A", "B", "C");
        }

        /// <summary>
        /// 汉诺塔
        /// </summary>
        /// <param name="n"></param>
        /// <param name="from"></param>
        /// <param name="ins"></param>
        /// <param name="to"></param>
        private void Hanoi(int n, string from, string ins, string to)
        {
            if (n == 1)
            {
                Console.WriteLine("第1盘从" + from + " 移动到 " + to);
            }
            else
            {
                //移动上面所有盘子到中间位置
                Hanoi(n - 1, from, to, ins);
                //移动下面的盘子
                Console.WriteLine("第" + n + "盘子从" + from + " 移动到 " + to);
                //把上面所有盘子从中间位置移动到目标位置
                Hanoi(n - 1, ins, from, to);
            }
        }
    }
}
